<?php namespace Admin\Controller; 

use Admin\Model\Brand;

class BrandController extends AuthController
{
	//数据连接驱动
	protected $db;

	//构造函数
	public function __init()
	{
		$this->db = new Brand;
	}
	
    //动作
    public function index()
    {
    	$data = $this->db->getAll();
    	View::with('data',$data);
        View::make();
    }

    //添加品牌方法
    public function add()
    {
    	if (IS_POST) 
    	{
    		if ($this->db->store()) 
    		{
    			$this->success('新增品牌成功','index');
    		}else{
    			$this->error($this->db->getError());
    		}
    	}
    	else{
    		View::make();
    	}
    	
    }

    //编辑品牌的方法
    public function edit()
   	{
   		if (IS_POST) 
   		{
   			if($this->db->edit())
   			{
   				$this->success('修改成功','index');
   			}else{
   				$this->error($this->db->getError());
   			}

   		}
   		else{
   			$data = $this->db->only(Q('get.id'));
   			View::with('data',$data);
   			View::make();
   		}
   	}
}
